
package com.cms.service.impl;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.cms.dao.DormBuildDao;
import com.cms.entity.DormBuild;
import com.cms.service.DormBuildService;
import com.cms.utils.ExcelUtil;
import com.cms.utils.page.Pagination;

/**
 * @ClassName: DormBuildServiceImpl
 * @Description: TODO
 * @date 2021-02-27 15:43:23
 */
@Service
@Transactional
public class DormBuildServiceImpl implements DormBuildService {

    @Autowired
    private DormBuildDao dormBuildDao;

    /**
     * @see com.cms.service.DormBuildService#deleteByPrimaryKey(java.lang.String)
     * @Description: TODO
     * @param id
     * @return
     * @date 2021-02-27 15:43:23
     */
    @Override
    public int deleteByPrimaryKey(Integer id) {
        // TODO Auto-generated method stub
        return dormBuildDao.deleteByPrimaryKey(id);
    }

    /**
     * @see com.cms.service.DormBuildService#addStudent(com.cms.entity.DormBuild)
     * @Description: TODO
     * @param record
     * @return
     * @throws Exception
     * @date 2021-02-27 15:43:23
     */
    @Override
    public int addDormBuild(DormBuild record) throws Exception {
        // TODO Auto-generated method stub
        return dormBuildDao.insert(record);
    }

    /**
     * @see com.cms.service.DormBuildService#getTotalItemsCount(java.lang.String)
     * @Description: TODO
     * @param searchKey
     * @return
     * @date 2021-02-27 15:43:23
     */
    @Override
    public int getTotalItemsCount(String searchKey) {
        // TODO Auto-generated method stub
        System.out.println("DormBuildServiceImpl+getTotalItemsCount");
        return dormBuildDao.getTotalItemsCount(searchKey);
    }

    /**
     * @see com.cms.service.DormBuildService#selectDormBuild(java.lang.String)
     * @Description: TODO
     * @param id
     * @return
     * @date 2021-02-27 15:43:23
     */
    @Override
    public DormBuild selectDormBuild(String id) {
        // TODO Auto-generated method stub
        return dormBuildDao.selectByPrimaryKey(id);
    }

    /**
     * @see com.cms.service.DormBuildService#updateStudent(com.cms.entity.DormBuild)
     * @Description: TODO
     * @param record
     * @return
     * @date 2021-02-27 15:43:23
     */
    @Override
    public int updateDormBuild(DormBuild record) {
        // TODO Auto-generated method stub

        return dormBuildDao.updateByPrimaryKeySelective(record);
    }

    /**
     * @see com.cms.service.DormBuildService#getStudentList(com.cms.utils.page.Pagination, java.lang.String)
     * @Description: TODO
     * @param page
     * @param searchKey
     * @return
     * @date 2021-02-27 15:43:23
     */
    @Override
    public List<DormBuild> getDormBuildList(Pagination<DormBuild> page, String searchKey) {
        // TODO Auto-generated method stub

        return dormBuildDao.selectBySearchKey(page, searchKey);
    }

    /**
     * @see com.cms.service.DormBuildService#deleteDormBuild(java.util.List)
     * @Description: TODO
     * @param ids
     * @return
     * @date 2021-02-27 16:06:19
     */
    @Override
    public int deleteDormBuild(List<String> ids) {
        // TODO Auto-generated method stub
        System.out.println(ids);
        return dormBuildDao.deleteInList(ids);
    }

    @Override
    public int importExcelInfo(InputStream in, MultipartFile file) throws Exception {
        List<List<Object>> listob = ExcelUtil.getBankListByExcel(in, file.getOriginalFilename());
        List<DormBuild> list = new ArrayList<DormBuild>();
        // 遍历listob数据，把数据放到List中
        for (List<Object> ob : listob) {
            DormBuild dormBuild = new DormBuild();
            // 通过遍历实现把每一列封装成一个model中
            dormBuild.setDormBuildId((int)ob.get(0));
            dormBuild.setDormBuildName(String.valueOf(ob.get(1)));
            dormBuild.setDetail(String.valueOf(ob.get(2)));

            list.add(dormBuild);
        }
        return dormBuildDao.insertBatch(list);
    }

    /**
     * @see com.cms.service.DormBuildService#getDormBuildForSelect(java.lang.String)
     * @Description: TODO
     * @param searchKey
     * @return
     * @date 2021-02-28 11:02:57
     */
    @Override
    public List<DormBuild> getDormBuildForSelect(String searchKey) {
        // TODO Auto-generated method stub
        return dormBuildDao.getDormBuildForSelect(searchKey);
    }
}
